﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:user_adv
	/// </summary>
	public partial class user_adv
	{
		public user_adv()
		{}
		#region  Method
        public DataSet PageUserAdvHunter(int atid, int startid, int pagesize, out int count)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@atid", SqlDbType.Int,4),
                    new SqlParameter("@startIndex", SqlDbType.Int,4),
                    new SqlParameter("@endIndex", SqlDbType.Int,4),
                    new SqlParameter("@count", SqlDbType.Int,4)
};
            parameters[3].Direction = ParameterDirection.Output;
            parameters[0].Value = atid;
            parameters[1].Value = startid;
            parameters[2].Value = startid + pagesize - 1;
            DataSet ds = DbHelperSQL.RunProcedure("[dbo].[P_PageAdvHunter]", parameters, "ds");
            count = int.Parse(parameters[3].Value.ToString());
            return ds;
        }


		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("aid", "user_adv"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int aid)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4)
};
			parameters[0].Value = aid;

			int result= DbHelperSQL.RunProcedure("user_adv_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public int Add(lcmyjobs.Model.user_adv model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4),
					new SqlParameter("@abh", SqlDbType.Char,6),
					new SqlParameter("@uid", SqlDbType.Int,4),
					new SqlParameter("@yearpay", SqlDbType.Int,4),
					new SqlParameter("@advstatus", SqlDbType.Int,4),
					new SqlParameter("@advtime", SqlDbType.DateTime),
					new SqlParameter("@OKstatus", SqlDbType.Bit,1)};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = model.abh;
			parameters[2].Value = model.uid;
			parameters[3].Value = model.yearpay;
			parameters[4].Value = model.advstatus;
			parameters[5].Value = model.advtime;
			parameters[6].Value = model.OKstatus;

			DbHelperSQL.RunProcedure("user_adv_ADD",parameters,out rowsAffected);
			return (int)parameters[0].Value;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.user_adv model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4),
					new SqlParameter("@abh", SqlDbType.Char,6),
					new SqlParameter("@uid", SqlDbType.Int,4),
					new SqlParameter("@yearpay", SqlDbType.Int,4),
					new SqlParameter("@advstatus", SqlDbType.Int,4),
					new SqlParameter("@advtime", SqlDbType.DateTime),
					new SqlParameter("@OKstatus", SqlDbType.Bit,1)};
			parameters[0].Value = model.aid;
			parameters[1].Value = model.abh;
			parameters[2].Value = model.uid;
			parameters[3].Value = model.yearpay;
			parameters[4].Value = model.advstatus;
			parameters[5].Value = model.advtime;
			parameters[6].Value = model.OKstatus;

			DbHelperSQL.RunProcedure("user_adv_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int aid)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4)
};
			parameters[0].Value = aid;

			DbHelperSQL.RunProcedure("user_adv_Delete",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string aidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from user_adv ");
			strSql.Append(" where aid in ("+aidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.user_adv GetModel(int aid)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@aid", SqlDbType.Int,4)
};
			parameters[0].Value = aid;

			lcmyjobs.Model.user_adv model=new lcmyjobs.Model.user_adv();
			DataSet ds= DbHelperSQL.RunProcedure("user_adv_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["aid"]!=null && ds.Tables[0].Rows[0]["aid"].ToString()!="")
				{
					model.aid=int.Parse(ds.Tables[0].Rows[0]["aid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["abh"]!=null && ds.Tables[0].Rows[0]["abh"].ToString()!="")
				{
					model.abh=ds.Tables[0].Rows[0]["abh"].ToString();
				}
				if(ds.Tables[0].Rows[0]["uid"]!=null && ds.Tables[0].Rows[0]["uid"].ToString()!="")
				{
					model.uid=int.Parse(ds.Tables[0].Rows[0]["uid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["yearpay"]!=null && ds.Tables[0].Rows[0]["yearpay"].ToString()!="")
				{
					model.yearpay=int.Parse(ds.Tables[0].Rows[0]["yearpay"].ToString());
				}
				if(ds.Tables[0].Rows[0]["advstatus"]!=null && ds.Tables[0].Rows[0]["advstatus"].ToString()!="")
				{
					model.advstatus=int.Parse(ds.Tables[0].Rows[0]["advstatus"].ToString());
				}
				if(ds.Tables[0].Rows[0]["advtime"]!=null && ds.Tables[0].Rows[0]["advtime"].ToString()!="")
				{
					model.advtime=DateTime.Parse(ds.Tables[0].Rows[0]["advtime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["OKstatus"]!=null && ds.Tables[0].Rows[0]["OKstatus"].ToString()!="")
				{
					if((ds.Tables[0].Rows[0]["OKstatus"].ToString()=="1")||(ds.Tables[0].Rows[0]["OKstatus"].ToString().ToLower()=="true"))
					{
						model.OKstatus=true;
					}
					else
					{
						model.OKstatus=false;
					}
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select aid,abh,uid,yearpay,advstatus,advtime,OKstatus ");
			strSql.Append(" FROM user_adv ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" aid,abh,uid,yearpay,advstatus,advtime,OKstatus ");
			strSql.Append(" FROM user_adv ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "user_adv";
			parameters[1].Value = "aid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

